package com.yf.myException;

import com.yf.dto.Message;
import com.yf.dto.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionController {

    @ResponseBody
    @ExceptionHandler(value = {NewException.class})
    public Result commonException(NewException e){

        e.printStackTrace();

        Message message = new Message();

        message.setCode(e.getCode());
        message.setMsg(e.getMsg());

        Result result = new Result();

        result.setMessage(message);

        return  result;

    }


}
